Add multi-tenant Databricks token support via cross-namespace K8s secrets#3394
Merged
machichima merged 2 commits intoMar 10, 2026
Merged
Conversation
|
Thank you for opening this pull request! 🙌 These tips will help get your PR across the finish line:
|
3 tasks
pingsutw
approved these changes
Mar 4, 2026
Member
|
lgtm, thank you! Could you fix the lint errors? |
7ceb06f to
9eef1e0
Compare
pingsutw
approved these changes
Mar 4, 2026
9eef1e0 to
048ed2e
Compare
…space K8s secrets Enable per-project Databricks authentication by reading tokens from Kubernetes secrets in workflow namespaces, with backward-compatible fallback to the FLYTE_DATABRICKS_ACCESS_TOKEN environment variable. Changes: - Add get_secret_from_k8s() for cross-namespace K8s secret reading - Add get_databricks_token() with tiered resolution (K8s -> env var) - Update DatabricksJobMetadata to persist auth_token across lifecycle - Update DatabricksConnector.create/get/delete to use per-project tokens - Add DatabricksV2.databricks_token_secret for custom secret names - Add 31 comprehensive tests covering all token resolution paths Tracking: flyteorg/flyte#6911 Signed-off-by: Rohit Sharma <rohitrsh@gmail.com>
048ed2e to
0cfa9c8
Compare
Contributor
Author
Hey @pingsutw, so here's what I have done to fix the lint issue. Lint fix: Restored The lint CI was failing because Without the baseline, Pydoclint treated every pre-existing violation in the entire codebase as a new error, causing the failures in ruff, ruff-format, trailing-whitespace, and Pydoclint checks. What was done:
|
e13f8f9 to
1df2ae5
Compare
Resolve merge conflicts in task.py after flyteorg#3392 (serverless) was merged: - Combined DatabricksV2 attributes: kept all serverless fields, added databricks_token_secret - Combined get_custom() serialization for both feature sets - Added auth_token to serverless test metadata assertion - Removed emoji from error message Signed-off-by: Rohit Sharma <rohitrsh@gmail.com> Made-with: Cursor
1df2ae5 to
148e088
Compare
rohitrsh
added a commit
to rohitrsh/flytekit
that referenced
this pull request
Apr 30, 2026
… OIDC federation strategies Databricks has marked Personal Access Tokens (PATs) as a legacy auth method (https://docs.databricks.com/aws/en/dev-tools/auth/pat) and is steering customers toward OAuth machine-to-machine (M2M) and OIDC workload-identity federation. This change brings both modern auth modes to the Flyte Databricks connector and refactors the existing PAT support into a shared strategy module so all four modes resolve identically. What is added: * OAuth M2M (client credentials) using a per-namespace 'databricks-oauth' K8s secret with operator-level fallbacks via env vars. * OIDC federation, Model 1: the connector pod's own projected JWT (e.g. EKS IRSA) is exchanged for a Databricks bearer token. * OIDC federation, Model 2: per-workflow-namespace ServiceAccount discovery driven by labels and annotations on the SA. The connector mints a JWT via the Kubernetes TokenRequest API and exchanges it for a Databricks token. This preserves the existing per-namespace tenancy model that PAT customers rely on for Unity Catalog access. * A unified DatabricksAuth strategy abstraction in 'databricks_auth.py' with auto-detection, per-strategy token caching, and token refresh on 401 responses for long-running jobs. What changes for existing PAT users: * This PR refactors the PAT support that was added in flyteorg#3394 from a direct function call into a 'PATAuth' strategy that lives alongside the new modes. The behaviour, env vars, and per-namespace 'databricks-token' lookup are preserved end-to-end. Reviewers may want to read 'connector.py' and the new tests with this refactor in mind: PAT now flows through the same 'select_auth' resolver as the new modes so we have one extension point instead of two. * Workflow code is unchanged. 'DatabricksV2' gains optional override fields for power users, but existing tasks keep working without edits. Validation: * 'pytest plugins/flytekit-spark/tests/test_databricks_auth.py plugins/flytekit-spark/tests/test_databricks_token.py plugins/flytekit-spark/tests/test_connector.py' passes (100 tests). * End-to-end tested on an EKS test cluster against a real Databricks workspace for PAT, OAuth M2M, and OIDC Model 2. * Pre-commit (ruff, ruff-format, codespell, pydoclint) clean on the changed plugin files. Tracking: flyteorg/flyte#7319 Related: * flyteorg#3394 (PAT multi-tenancy, refactored here) * flyteorg#3392 (Databricks Serverless compute) * flyteorg/flyte#6911 (original PAT multi-tenancy issue) Signed-off-by: Rohit Sharma <rohitrsh@gmail.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tracking issue
Related to flyteorg/flyte#6911
Why are the changes needed?
The Databricks Spark connector currently uses a single global
FLYTE_DATABRICKS_ACCESS_TOKENenvironment variable for authenticating all Databricks API calls. This creates significant limitations for multi-tenant Flyte deployments:This PR adds per-project Databricks token support by enabling the connector to read tokens from Kubernetes secrets in the workflow's project namespace, with backwards-compatible fallback to the existing environment variable.
What changes were proposed in this pull request?
Token Resolution Strategy
The connector now resolves Databricks tokens using a tiered strategy:
databricks-token, key:token) from the workflow's Kubernetes namespace using cross-namespace lookup.FLYTE_DATABRICKS_ACCESS_TOKENif no namespace secret is found.Changes
connector.py:get_secret_from_k8s(secret_name, secret_key, namespace)Cross-namespace K8s secret reader using the Kubernetes Python client. Tries in-cluster config first, falls back to kubeconfig for local development.get_databricks_token(namespace, task_template, secret_name). Implements the token resolution strategy with structured logging and error handling.get_header()Now accepts an optionalauth_tokenparameter.DatabricksJobMetadataAddedauth_tokenfield to persist the resolved token across create/get/delete operations.DatabricksConnector.create(). Now acceptstask_execution_metadataparameter, extracts the namespace, and resolves the project-specific token.DatabricksConnector.get()/delete()Use storedauth_tokenfrom metadata.task.py:databricks_token_secretfield toDatabricksV2Allows users to specify a custom K8S secret name per task.get_custom()SerialisesdatabricksTokenSecretinto the task template custom dict.User Experience
No changes needed for existing users Existing workflows continue to work with the global
FLYTE_DATABRICKS_ACCESS_TOKEN.New capability for multi-tenant setups:
How was this patch tested?
Unit Tests (
test_databricks_token.py)30+ test cases covering:
get_secret_from_k8s:get_databricks_token:get_header:DatabricksJobMetadata:DatabricksConnector:DatabricksV2task config:Setup process
getpermission on secrets across namespaces:kubectl create secret generic databricks-token \ --from-literal=token='your-token' \ --namespace=your-project-namespaceScreenshots
N/A (backend-only change)
Check all the applicable boxes
Related PRs
Docs link
N/A